﻿/*
	Copyright (c) 2013 Andrew Meyer

	Permission is hereby granted, free of charge, to any person obtaining a copy of this software
	and associated documentation files (the "Software"), to deal in the Software without
	restriction, including without limitation the right to use, copy, modify, merge, publish,
	distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
	Software is furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all copies or
	substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
	BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
	DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Media3D;

namespace Ascend
{
	/// <summary>
	/// Handler definition for Ascend.SceneNode mouse events.
	/// </summary>
	/// <param name="sender">The source of the event.</param>
	/// <param name="e">The event args associated with the event.</param>
	public delegate void SceneNodeMouseEventHandler(object sender, SceneNodeMouseEventArgs e);


	/// <summary>
	/// Arguments for use in Ascend.SceneNode mouse event handlers. This class cannot be inherited
	/// externally.
	/// </summary>
	public class SceneNodeMouseEventArgs : EventArgs
	{
		#region Lifecycle
		internal SceneNodeMouseEventArgs(MouseEventArgs e, SceneViewer3D viewer,
			ModelSceneNode source, RayHitTestResult result)
		{
			_sourceArgs = e;
			SceneViewer = viewer;
			Source = source;
			HitTestResult = result;
		}
		#endregion

		#region Protected Members
		protected MouseEventArgs _sourceArgs;
		#endregion

		#region Public Properties
		/// <summary>
		/// Gets the Ascend.SceneViewer3D that contains the hit Ascend.SceneNode.
		/// </summary>
		public SceneViewer3D SceneViewer
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets the System.Windows.Input.InputDevice associated with this event.
		/// </summary>
		public InputDevice Device
		{
			get
			{
				return _sourceArgs.Device;
			}
		}

		/// <summary>
		/// Gets the System.Windows.Input.MouseDevice associated with this event.
		/// </summary>
		public MouseDevice MouseDevice
		{
			get
			{
				return _sourceArgs.MouseDevice;
			}
		}

		/// <summary>
		/// Gets the System.Windows.Input.StylusDevice associated with this event.
		/// </summary>
		public StylusDevice StylusDevice
		{
			get
			{
				return _sourceArgs.StylusDevice;
			}
		}

		/// <summary>
		/// Gets the state of the left mouse button.
		/// </summary>
		public MouseButtonState LeftButton
		{
			get
			{
				return _sourceArgs.LeftButton;
			}
		}

		/// <summary>
		/// Gets the current state of the middle mouse button.
		/// </summary>
		public MouseButtonState MiddleButton
		{
			get
			{
				return _sourceArgs.MiddleButton;
			}
		}

		/// <summary>
		/// Gets the current state of the right mouse button.
		/// </summary>
		public MouseButtonState RightButton
		{
			get
			{
				return _sourceArgs.RightButton;
			}
		}

		/// <summary>
		/// Gets the current state of the first extended mouse button.
		/// </summary>
		public MouseButtonState XButton1
		{
			get
			{
				return _sourceArgs.XButton1;
			}
		}

		/// <summary>
		/// Gets the current state of the second extended mouse button.
		/// </summary>
		public MouseButtonState XButton2
		{
			get
			{
				return _sourceArgs.XButton2;
			}
		}

		/// <summary>
		/// Gets the time when the event occurred.
		/// </summary>
		public int Timestamp
		{
			get
			{
				return _sourceArgs.Timestamp;
			}
		}

		/// <summary>
		/// Gets the Ascend.ModelSceneNode that initiated the event.
		/// </summary>
		public ModelSceneNode Source
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets the System.Windows.Media.Media3D.RayHitTestResult associated with this event.
		/// </summary>
		public RayHitTestResult HitTestResult
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets or sets whether this event was handled.
		/// </summary>
		/// <remarks>
		/// If this value is set to false, further event handlers will not be triggered.
		/// </remarks>
		public bool Handled
		{
			get;
			set;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Gets the position of the mouse pointer relative to the specified element.
		/// </summary>
		/// <param name="relativeTo">
		/// The element to use as the frame of reference for calculating the position of the mouse
		/// pointer.
		/// </param>
		/// <returns>
		/// Returns the x- and y-coordinates of the mouse pointer position relative to the specified
		/// object.
		/// </returns>
		public Point GetPosition(IInputElement relativeTo)
		{
			return _sourceArgs.GetPosition(relativeTo);
		}

		/// <summary>
		/// Returns the position of the mouse pointer relative to the Ascend.SceneViewer3D that
		/// contains the hit Ascend.SceneNode.
		/// </summary>
		public Point GetPosition()
		{
			return _sourceArgs.GetPosition(SceneViewer);
		}
		#endregion
	}
}
